package model

import (
	"awesomeProject2/global"
	"gorm.io/gorm"
)

type Achievement struct {
	gorm.Model
	AchievementLevel    string `json:"achievementLevel" form:"achievementLevel" gorm:"type:varchar(255);"`
	AchievementName     string `json:"achievementName"  form:"achievementName" gorm:"type:varchar(255);"`
	AchievementCategory string `json:"achievementCategory" form:"achievementCategory" gorm:"type:varchar(255)"`
	//AchievementScore    int    `json:"achievementScore" form:"achievementScore" gorm:"column:achievementScore;comment:;type:int"`
	AchievementFrom    string `json:"achievementFrom"  gorm:"type:varchar(255);"`
	AchievementFile    string `json:"achievementFile"  gorm:"type:varchar(255);"`
	AchievementRanking int    `json:"achievementRanking"  gorm:"type:int"`
	UserId             uint   `json:"userid"  gorm:"type:bigint"`
	IsVisible          bool   `json:"is_visible"  gorm:"type:tinyint"`
	Year               int    `json:"year" form:"year" gorm:"type:int"`
	ID                 uint
}

// GetAllac 统计总数目
func GetAllac(year int) (error, int64) {
	var tt int64
	err := global.GVA_DB.Model(&Achievement{}).Where("year = ?", year).Count(&tt).Error
	return err, tt
}

func GetAllAchievements(id uint) (error, interface{}, int64) {
	var data []Achievement
	var tt int64
	err := global.GVA_DB.Where("user_id = ? ", id).Find(&data).Count(&tt).Error
	return err, data, tt
}
